home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ May 89 / U0028-Re Specializing fie-May89 < prev    next >
Encoding:
Text File  |  1989-06-26  |  1.1 KB  |  48 lines  |  [TEXT/GEOL]

  1. Item    2290855                         16-May-89        16:25
  2.  
  3. From:   PASCOE1                         Pascoe, Geoff
  4.  
  5. To:     MACAPP.TECH$                    MACAPP Tech
  6.  
  7. Sub:    Re to Specializing fields
  8.  
  9. Alan, Howard, and Joel-
  10.  
  11. I think changing the names of instance variables like this is probably not
  12. such a great idea.  I agree with Howard that this can make reading code really
  13. hard.  However, Trellis allows you to redeclare an instance variable in
  14. a subclass as long as that variable conforms to the superclass type (i.e.,
  15. is a subclass of it.  For example,
  16.  
  17. TA = OBJECT(TObject)
  18.     :
  19.     :
  20. END;
  21.  
  22. TB = OBJECT(TA)
  23.     :
  24.     :
  25. END;
  26.  
  27. TC = OBJECT(TObject)
  28.     fInstVar : TA;
  29.     :
  30.     :
  31. END;
  32.  
  33. TD = OBJECT(TC)
  34.     fInstVar : TB;
  35.     :
  36.     :
  37. END;
  38.  
  39. Since TB conforms to TA because it is a subclass of TA, we can redeclare it
  40. to be more specialized when it is an instance variable.
  41.  
  42. Unfortunately you can't do this in Object Pascal or C++.  Typically,
  43. programmers will either create another, parallel, instance variable of
  44. the proper type or cast it when it's is used in the more specialized way.
  45.  
  46. Geoff
  47.  
  48.